package com.czxy.controller;

import com.czxy.domain.Rose;
import com.czxy.domain.Staff;
import com.czxy.domain.StaffVo;
import com.czxy.service.StaffService;
import com.czxy.vo.BaseResult;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/2/3
 */
@RestController
@RequestMapping("/staff")
public class StaffController {
    @Resource
    private StaffService staffService;

    //后台登陆
    @PostMapping("/login")
    public BaseResult login(@RequestBody Staff staff){
        Staff staff1 = staffService.login(staff);
        if (staff1 == null){
            return BaseResult.error("用户名或密码错误");
        }
        return BaseResult.ok("登录成功",staff1);
    }

    //查询所有角色
    @GetMapping("/findAllRose")
    public BaseResult findAllRose(){
        List<Rose> roseList = staffService.findAllRose();
        return BaseResult.ok("查询成功",roseList);
    }

    //分页 + 条件 查询  酒店员工管理 登录后台使用
    @PostMapping("/findAllStaffForpage")
    public BaseResult<PageInfo<Staff>> findAllStaffForpage(@RequestBody StaffVo staffVo){
        PageInfo<Staff> staffPageInfo = staffService.findAllStaffForpage(staffVo);
        return BaseResult.ok("查询成功",staffPageInfo);
    }

    //增加 添加有一个酒店员工 以便进行后台操作
    @PostMapping("/addStaff")
    public BaseResult addStaff(@RequestBody Staff staff){
        staffService.addStaff(staff);
        return BaseResult.ok("添加成功");
    }

    //删除
    @DeleteMapping("/delStaffByHid/{hid}")
    public BaseResult delStaffByHid(@PathVariable("hid") Integer hid){
        staffService.delStaffByHid(hid);
        return BaseResult.ok("删除成功");
    }

    //批量删除 传入字符串
    @DeleteMapping("/delAllStaffByDir/{dir}")
    public BaseResult delAllStaffByDir(@PathVariable("dir")String dir){
        staffService.delAllStaffByDir(dir);
        return BaseResult.ok("批量删除成功");
    }

    //修改一 根据 传入的 hid 查找到用户
    @GetMapping("/findOneStaffByhid/{hid}")
    public BaseResult findOneStaffByhid(@PathVariable("hid") Integer hid){
        Staff staff = staffService.findOneStaffByhid(hid);
        return BaseResult.ok("查询成功",staff);
    }

    //修改二 真正修改
    @PutMapping("/updateStaff")
    public BaseResult updateStaff(@RequestBody Staff staff){
        staffService.updateStaff(staff);
        return BaseResult.ok("修改成功");
    }

}
